package icecreamtest;
import swa2.icecream.IceCream;
import swa2.icecream.command.CherryOffCommand;
import swa2.icecream.command.CherryOnCommand;
import swa2.icecream.command.ChocolateOffCommand;
import swa2.icecream.command.ChocolateOnCommand;
import swa2.icecream.command.Command;
import swa2.icecream.command.CreateIceCreamCommand;
import swa2.icecream.command.CreateIceCreamSpeciale;
import swa2.icecream.command.Invoker;
import swa2.icecream.command.NoActionCommand;
import swa2.icecream.factory.AbstractIceCreamFactory;
import swa2.icecream.factory.GreekIceCreamFactory;
import swa2.icecream.factory.ItalianIceCreamFactory;

public class IcecreamTest
{
	public static void main(String args[])
	{
		/*
		 * * * Custom Italian ice cream * * *
		 */
		AbstractIceCreamFactory shop = new ItalianIceCreamFactory();
		Invoker invoker = createInvoker(shop);
		
		invoker.executeOnCmd(0); // cherry on
		
		invoker.executeOnCmd(1); // chocolate on
		invoker.executeOnCmd(1); // chocolate on
		invoker.executeOnCmd(1); // chocolate on
		
		invoker.executeOnCmd(2); // create icecream;
		
		IceCream iic = shop.getIceCream();
		System.out.println(iic.getDescription() + ": " + iic.getPrice());
		
		invoker.executeOnCmd(3); // create icecream speciale;
		
		/*
		 * * * Ice cream Speciale * * *
		 */
		IceCream ics = shop.getIceCream();
		System.out.println(ics.getDescription() + ": " + ics.getPrice());
		
		/*
		 * * * * Custom Greek ice creeam * * *
		 */
		shop = new GreekIceCreamFactory();
		invoker = createInvoker(shop);
		
		invoker.executeOnCmd(0); // cherry on
		invoker.executeUndoCmd(); // undo cherry on
		
		invoker.executeOnCmd(1); // chocolate on
		invoker.executeOnCmd(1); // chocolate on
		invoker.executeOnCmd(0); // cherry on
		invoker.executeOnCmd(1); // chocolate on
		invoker.executeUndoCmd(); // undo chocolate on
		invoker.executeUndoCmd(); // undo cherry on
		
		invoker.executeOnCmd(2); // create icecream;
		
		IceCream gic = shop.getIceCream();
		System.out.println(gic.getDescription() + ": " + gic.getPrice());
	}
	
	public static Invoker createInvoker(AbstractIceCreamFactory factory)
	{
		Invoker invoker = new Invoker();
		
		Command cherryOn = new CherryOnCommand(factory);
		Command cherryOff = new CherryOffCommand(factory);
		Command chocolateOn = new ChocolateOnCommand(factory);
		Command chocolateOff = new ChocolateOffCommand(factory);
		Command createIceCream = new CreateIceCreamCommand(factory);
		Command createSpeciale = new CreateIceCreamSpeciale(factory);
		Command none = new NoActionCommand();
		
		invoker.setCommand(0, cherryOn, cherryOff);
		invoker.setCommand(1, chocolateOn, chocolateOff);
		invoker.setCommand(2, createIceCream, none);
		invoker.setCommand(3, createSpeciale, none);
		
		return invoker;
	}
}
